/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package z.h.w.jar.kit.clazz;

import java.util.List;

/**
 *
 * @param <Type>
 *
 * @author EnzoZhong
 */
public class Split<Type> {

      private List<Type> list;
      private Integer split;
      private Integer size;
      private Integer index = 0;
      private Integer s = 0;
      private Integer e;

      public Split ( List<Type> list , Integer split ) {
            this.split = split;
            this.list = list;
            this.size = list.size ();
            this.e = split;
      }

      public List<Type> next () {
            s = calS ();
            e = calE ();
            index ++;
            return list.subList ( s , e );
      }

      private Integer calS () {
            return index * split > size - 1 ? size - 1 : index * split;
      }

      private Integer calE () {
            return ( index + 1 ) * split > size ? size : ( index + 1 ) * split;
      }

      public Boolean hasNext () {
            if ( e >= size ) {
                  return false;
            }
            return true;
      }

}
